package com.ruoyi.report_jl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.syrw.annotation.FIllBasicInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_jl.domain.bo.ReportJlXjlf075chlsyBsInfoBo;
import com.ruoyi.report_jl.domain.vo.ReportJlXjlf075chlsyBsInfoVo;
import com.ruoyi.report_jl.domain.ReportJlXjlf075chlsyBsInfo;
import com.ruoyi.report_jl.mapper.ReportJlXjlf075chlsyBsInfoMapper;
import com.ruoyi.report_jl.service.IReportJlXjlf075chlsyBsInfoService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 细集料0.075mm以下粉尘含量试验检测记录Service业务层处理
 *
 * @author zyb
 * @date 2024-12-11
 */
@RequiredArgsConstructor
@Service
@DSTransactional
public class ReportJlXjlf075chlsyBsInfoServiceImpl implements IReportJlXjlf075chlsyBsInfoService {

    private final ReportJlXjlf075chlsyBsInfoMapper baseMapper;

    /**
     * 查询细集料0.075mm以下粉尘含量试验检测记录
     */
    @Override
    @FIllBasicInfo
    public ReportJlXjlf075chlsyBsInfoVo queryById(Long excelId){
        return baseMapper.selectVoById(excelId);
    }

    /**
     * 查询细集料0.075mm以下粉尘含量试验检测记录列表
     */
    @Override
    public TableDataInfo<ReportJlXjlf075chlsyBsInfoVo> queryPageList(ReportJlXjlf075chlsyBsInfoBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportJlXjlf075chlsyBsInfo> lqw = buildQueryWrapper(bo);
        Page<ReportJlXjlf075chlsyBsInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询细集料0.075mm以下粉尘含量试验检测记录列表
     */
    @Override
    public List<ReportJlXjlf075chlsyBsInfoVo> queryList(ReportJlXjlf075chlsyBsInfoBo bo) {
        LambdaQueryWrapper<ReportJlXjlf075chlsyBsInfo> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportJlXjlf075chlsyBsInfo> buildQueryWrapper(ReportJlXjlf075chlsyBsInfoBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportJlXjlf075chlsyBsInfo> lqw = Wrappers.lambdaQuery();
//        lqw.eq(bo.getTotalPage() != null, ReportJlXjlf075chlsyBsInfo::getTotalPage, bo.getTotalPage());
//        lqw.eq(bo.getPage() != null, ReportJlXjlf075chlsyBsInfo::getPage, bo.getPage());
//        lqw.eq(StringUtils.isNotBlank(bo.getJilbh()), ReportJlXjlf075chlsyBsInfo::getJilbh, bo.getJilbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancdwmc()), ReportJlXjlf075chlsyBsInfo::getJiancdwmc, bo.getJiancdwmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getGongcmc()), ReportJlXjlf075chlsyBsInfo::getGongcmc, bo.getGongcmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getGongcbwyt()), ReportJlXjlf075chlsyBsInfo::getGongcbwyt, bo.getGongcbwyt());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpmc()), ReportJlXjlf075chlsyBsInfo::getYangpmc, bo.getYangpmc());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpbh()), ReportJlXjlf075chlsyBsInfo::getYangpbh, bo.getYangpbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpsl()), ReportJlXjlf075chlsyBsInfo::getYangpsl, bo.getYangpsl());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpzt()), ReportJlXjlf075chlsyBsInfo::getYangpzt, bo.getYangpzt());
//        lqw.eq(StringUtils.isNotBlank(bo.getYangpsj()), ReportJlXjlf075chlsyBsInfo::getYangpsj, bo.getYangpsj());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiyjcrq()), ReportJlXjlf075chlsyBsInfo::getShiyjcrq, bo.getShiyjcrq());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiytjwd()), ReportJlXjlf075chlsyBsInfo::getShiytjwd, bo.getShiytjwd());
//        lqw.eq(StringUtils.isNotBlank(bo.getShiytjsd()), ReportJlXjlf075chlsyBsInfo::getShiytjsd, bo.getShiytjsd());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancyj()), ReportJlXjlf075chlsyBsInfo::getJiancyj, bo.getJiancyj());
//        lqw.eq(StringUtils.isNotBlank(bo.getPandyj()), ReportJlXjlf075chlsyBsInfo::getPandyj, bo.getPandyj());
//        lqw.eq(StringUtils.isNotBlank(bo.getJiancyjIds()), ReportJlXjlf075chlsyBsInfo::getJiancyjIds, bo.getJiancyjIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getPandyjIds()), ReportJlXjlf075chlsyBsInfo::getPandyjIds, bo.getPandyjIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getZhuyyqsbmcjbh()), ReportJlXjlf075chlsyBsInfo::getZhuyyqsbmcjbh, bo.getZhuyyqsbmcjbh());
//        lqw.eq(StringUtils.isNotBlank(bo.getShebIds()), ReportJlXjlf075chlsyBsInfo::getShebIds, bo.getShebIds());
//        lqw.eq(StringUtils.isNotBlank(bo.getFujsm()), ReportJlXjlf075chlsyBsInfo::getFujsm, bo.getFujsm());
//        lqw.eq(bo.getJiancjg() != null, ReportJlXjlf075chlsyBsInfo::getJiancjg, bo.getJiancjg());
//        lqw.eq(StringUtils.isNotBlank(bo.getQuydd()), ReportJlXjlf075chlsyBsInfo::getQuydd, bo.getQuydd());
//        lqw.eq(StringUtils.isNotBlank(bo.getDaibsl()), ReportJlXjlf075chlsyBsInfo::getDaibsl, bo.getDaibsl());
//        lqw.eq(StringUtils.isNotBlank(bo.getJincrq()), ReportJlXjlf075chlsyBsInfo::getJincrq, bo.getJincrq());
//        lqw.eq(StringUtils.isNotBlank(bo.getCd()), ReportJlXjlf075chlsyBsInfo::getCd, bo.getCd());
//        lqw.eq(StringUtils.isNotBlank(bo.getA1()), ReportJlXjlf075chlsyBsInfo::getA1, bo.getA1());
//        lqw.eq(StringUtils.isNotBlank(bo.getB1()), ReportJlXjlf075chlsyBsInfo::getB1, bo.getB1());
//        lqw.eq(StringUtils.isNotBlank(bo.getC1()), ReportJlXjlf075chlsyBsInfo::getC1, bo.getC1());
//        lqw.eq(StringUtils.isNotBlank(bo.getA2()), ReportJlXjlf075chlsyBsInfo::getA2, bo.getA2());
//        lqw.eq(StringUtils.isNotBlank(bo.getB2()), ReportJlXjlf075chlsyBsInfo::getB2, bo.getB2());
//        lqw.eq(StringUtils.isNotBlank(bo.getC2()), ReportJlXjlf075chlsyBsInfo::getC2, bo.getC2());
//        lqw.eq(StringUtils.isNotBlank(bo.getD1()), ReportJlXjlf075chlsyBsInfo::getD1, bo.getD1());
        return lqw;
    }

    /**
     * 新增细集料0.075mm以下粉尘含量试验检测记录
     */
    @Override
    public Boolean insertByBo(ReportJlXjlf075chlsyBsInfoBo bo) {
        ReportJlXjlf075chlsyBsInfo add = BeanUtil.toBean(bo, ReportJlXjlf075chlsyBsInfo.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setExcelId(add.getExcelId());
        }
        return flag;
    }

    /**
     * 修改细集料0.075mm以下粉尘含量试验检测记录
     */
    @Override
    public Boolean updateByBo(ReportJlXjlf075chlsyBsInfoBo bo) {
        ReportJlXjlf075chlsyBsInfo update = BeanUtil.toBean(bo, ReportJlXjlf075chlsyBsInfo.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportJlXjlf075chlsyBsInfo entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除细集料0.075mm以下粉尘含量试验检测记录
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
